from django.shortcuts import render
from rest_framework.generics import GenericAPIView, ListAPIView
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.mixins import ListModelMixin

from goods.models import SKU
from goods.serializers import SKUSerializer


# Create your views here.


# GET /categories/(?P<category_id>)/skus/
class SKUListView(ListAPIView):
    serializer_class = SKUSerializer
    # queryset = SKU.objects.filter(category_id=category_id)

    def get_queryset(self):
        """淡灰第三级分类id分类SKU商品的数据"""
        category_id = self.kwargs['category_id']
        return SKU.objects.filter(category_id=category_id)

    # def get(self, request,category_id):
    #     """
    #     self.kwargs: 字典, 保存从url地址中提取的所有命令参数
    #     根据第三级分类ID获取分类SKU商品的数据
    #     1.根据'category_id'获取分类SKU商品数据
    #     2.将商品序列化并返回
    #     """
    #     # 1.根据'category_id'获取分类SKU商品数据
    #     # skus = SKU.objects.filter(category_id=category_id)
    #     skus = self.get_queryset()
    #
    #     # 2.将商品序列化并返回
    #     serializer = self.get_serializer(skus, many=True)
    #     return Response(serializer.data)